<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;
use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;

class Product extends Model implements Sortable
{
	use HasDateTimeFormatter,SortableTrait;

    protected $casts = [
        'labels'=>'json',
        'atlas'=>'json',
        'prohibited_guests'=>'json',
        'gift_specific_service'=>'json',
    ];

    const SPECIFIC_SERVICE = [
        1=>'三光',
        2=>'無魔',
        3=>'陪洗香香',
        4=>'音樂',
        5=>'體育',
        6=>'素股',
        7=>'爆米花',
        8=>'冰火五重天',
        9=>'毒龍',
        0=>'自定義'
    ];

    const SPECIFIC_NOT_SERVICE = [
        1=>'預約送精美禮物',
        2=>'預約送小禮物',
        3=>'預約送驚喜喲',
        4=>'預約送小驚喜唷',
        5=>'預約送大驚喜唷',
        6=>'預約服務送到滿',
        7=>'預約全套送到底',
        8=>'預約套餐吃到飽',
        0=>'自定義'
    ];

    const PROHIBITED_GUESTS = [
        1=>'粗魯客',
        2=>'職業客',
        3=>'老司機'
    ];

    const HAIRSTYLE = [
        1=>'長髮',
        2=>'短髮'
    ];


    protected $fillable = [
        'team_id','name','img','height','weight','cup','photo','atlas','name_map','name_map_rotate','name_map_position','name_class','three_map','three_map_rotate','three_map_position','three_separator','three_class','video','video_cover','audio','audio_duration','detail','status','source',
        'scheduling','is_secretly','is_specific_service','gift_specific_service','custom_service','gift_not_specific_service','custom_service2','prohibited_guests','tags','hairstyle','video_authentication','show_video','price','labels'
    ];

    protected $sortable = [
        // 设置排序字段名称
        'order_column_name' => 'sort',
        // 是否在创建时自动排序，此参数建议设置为true
        'sort_when_creating' => true,
    ];

    public function tags()
    {
        return $this->belongsToMany(Tag::class,'product_tags','product_id','tag_id');
    }

    public function category()
    {
        $pivotTable = 'product_category'; // 中间表

        $relatedModel = Category::class;

        return $this->belongsToMany($relatedModel, $pivotTable, 'product_id', 'category_id');
    }

    public function team(){
        return $this->belongsTo(Team::class);
    }

    public function font(){
        return $this->belongsTo(Font::class);
    }
}
